'''
Created on Nov 19, 2010

@author: namikata
'''

import pygame
from pygame.locals import *
from gameobjects.vector2 import Vector2
from bk.pygame.ships.game.base.GameEntity import *
from bk.pygame.ships.game.Armory import *

class GBullet(GameEntity):
    '''
    classdocs
    '''

    def __init__(self,objclass, objsclass, data, parent):
        '''
        Constructor
        '''
        GameEntity.__init__(self, parent.world, data.id, parent.world.resources.dic[data.image], objclass, objsclass)
        
        self.data = data
        self.parent = parent
        self.location = Vector2(*parent.location)
        self.speed = data.speed
        self.max_speed = 150.
        self.movement_type = KMOV_DIRECTION
        self.cursor = None
        self.scale = data.scale

        self.location = parent.location + data.position_offset
        self.location = rotate_at_point(self.location, parent.location, -parent.rotation)
        
        self.direction = parent.cursor.location + data.position_offset
        self.direction = rotate_at_point(self.direction, parent.cursor.location, -parent.rotation + data.angle_offset)
        self.direction = self.direction - self.location
                
    def update(self,elapsed, keyboard, mouse):       
        GameEntity.update(self, elapsed)
        if not self.parent.world.is_inside_bounds(self.location):
            self.destroy = True